package com.kgc.community.service.impl;

import com.kgc.community.mapper.UserMapper;
import com.kgc.community.pojo.User;
import com.kgc.community.pojo.UserExample;
import com.kgc.community.service.UserService;
import com.kgc.community.utils.MyMD5;
import org.apache.ibatis.jdbc.Null;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Mr.Man
 * @Date 2020-11-26 8:52
 **/
@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    /**
     * 登录方法 使用Md5加密工具加密
     * @param username
     * @param pwd
     * @return
     */
    @Override
    public User login(String username, String pwd) {
        UserExample userExample = new UserExample();
        String s = MyMD5.MD5(pwd);
        userExample.createCriteria().andTelEqualTo(username).andPwdEqualTo(s);
        List<User> users = userMapper.selectByExample(userExample);
        if(users!=null){
            return users.size()>0?users.get(0):null;
        }
        return null;
    }
}
